package com.newer.his.BasicData.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newer.his.common.entity.Dept;
import com.newer.his.common.mapper.DeptMapper;


/**
 * 
 * 科室控制器
 *
 */

@RestController
@RequestMapping("/dept")
public class DeptController {

	@Autowired
	DeptMapper mapper;

	@GetMapping
	public List<Dept> getAllDept(){
		return mapper.findAll();
	}
	
	@GetMapping("/{id}")
	public Dept getDeptById(@PathVariable int id) {
		return mapper.findbyId(id);
		
	}
	
	 @PostMapping
	public Dept addDept(Dept dept) {
		mapper.save(dept);
		return dept;
		
	}
	 @PutMapping("/{id}")
	public  void updateDept(@PathVariable int id,
			@RequestBody Dept dept) {
		 dept.setId(id);
		mapper.update(dept);
		
	}
	 @DeleteMapping("/{id}")
	public  void deleteDept(@PathVariable int id) {
		mapper.delete(id);
	
	

}
	
	
}
